<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
	</head>
	<style type="text/css">
		*{
			margin: 0;
			padding: 0;
		}
	</style>
	<link rel="stylesheet" type="text/css" href="../js/layui/css/layui.css"/>
	
	<body>
		<div class="layui-container">
			<div  class="layui-row">
				<div class="layui-col-md6 layui-col-lg-offset3" style="margin-top: 20px;">
					<fieldset class="layui-elem-field" style="margin-top: 20px;">
					  <legend>更改密码</legend>
					  <div class="layui-form">
					  	<form  action="" method="POST" class="layui-form">
								<!-- 旧密码 -->
					  		<div class="layui-form" style="margin: 20px;">
					  			<label class="layui-form-label">旧密码：</label>
					  			<div class="layui-input-block">
					  				<input type="password" name="old_password" class="layui-input" lay-verify="required|password" lay-reqtext="确认密码不能为空" placeholder="请输入旧密码" autocomplete="off"  />
					  			</div>
					  		</div>
								
					  		<div class="layui-form" style="margin: 20px;">
					  			<label class="layui-form-label">新密码：</label>
					  			<div class="layui-input-block">
					  				<input type="password" id="pass1" name="password_1" class="layui-input" lay-verify="required|password" lay-reqtext="密码不能为空" placeholder="请输入新密码" autocomplete="off"  />
					  			</div>
					  		</div>
					  		
								<div class="layui-form" style="margin: 20px;">
									<label class="layui-form-label">确认密码：</label>
									<div class="layui-input-block">
										<input type="password" id="pass2" name="password_2" class="layui-input" lay-verify="required|password2" lay-reqtext="密码不能为空" placeholder="请输入新密码" autocomplete="off"  />
									</div>
								</div>
					  		<!-- submit -->
					  		<div class="layui-form" style="margin: 20px;">
					  			<div class="layui-input-block">
					  				<input type="submit"  class="layui-btn layui-btn-normal"  lay-submit lay-filter="submit_button" style="width: 100% ;" value="更改密码"/>
					  			</div>
					  		</div>
					  	</form>
					  </div>
					</fieldset>
		
				</div>
			</div>
		</div>
		
		<script type="text/javascript" src="../js/layui/layui.js"></script>
		<script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/md5.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			layui.use(['layer', 'form', 'element'],function(){
				//加载layui表单元素
				var form = layui.form,
					layer = layui.layer,
					element = layui.element; 
				form.render();
				
				form.verify({
					password: [/^[\S]{6,12}$/,'密码必须6到12位，且不能出现空格'],
					password2 : function(value){
						var pass2_value = $("#pass1").val();
						if(pass2_value != value){
							return '两次新密码不正确'
						}
					},
				});
				
				form.on("submit(submit_button)", function (data) {
					var k = JSON.stringify({
							re_pass : hex_md5(data.field.old_password),//旧密码
							new_pass : hex_md5(data.field.password_1),//新密码
							new_re_pass : hex_md5(data.field.password_2),//确认密码
							identify : 'doctor',
							phone : localStorage.getItem("FDSMS")
						});
						console.log(k);
					$.ajax({
						url:'http://123.56.67.48:8080/changePassword',
						method:'POST',
						contentType:'application/json',//15819426264
						data:k,
						success:function(res){
							var k = JSON.parse(res);
							alert(k.msg);
						},              
						error:function (res) {
							console.log("失败"); 
						}           
					}); 
					return false;		
				});
			});
		</script>
	</body>
</html>